package org.tloss.web.editor.model.command;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

import org.tloss.web.editor.model.LogicalProvider;
import org.tloss.web.editor.model.oper.logical.Logical;

@XmlAccessorType(XmlAccessType.PROPERTY)
public class If extends ComplexCommand implements LogicalProvider {
	private List<Logical> logicals;

	@XmlElementWrapper(name = "logicals")
	@XmlElement(name = "logical")
	public List<Logical> getLogicals() {
		return logicals;
	}

	public void setLogicals(List<Logical> logicals) {
		this.logicals = logicals;
	}

	public String getLabel() {
		if (logicals == null || logicals.size() == 0) {
			return "If[]";
		} else {
			return "If[" + logicals.get(0).getDisplayText() + "]";
		}
	}

	@Override
	public String generateBegin(int type, Object[] data) {
		if (logicals == null || logicals.size() == 0) {
			return "if(){";
		}
		return "if("+logicals.get(0).generate(type, data)+"){";
	}

	@Override
	public String generateEnd(int type, Object[] data) {
		return "}";
	}

}
